<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CreateLiveStream;
use App\Goodssmall\Goodssmall;
use App\Models\anchor;
use App\Models\StoreGood;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CreateLiveStreamController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CreateLiveStream(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('live_broadcast_title');
            $grid->column('live_broadcast_message');
            $grid->column('cover_picture')->image();
            $grid->column('goods_id');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CreateLiveStream(), function (Show $show) {
            $show->field('id');
            $show->field('live_broadcast_title');
            $show->field('live_broadcast_message');
            $show->field('anchor');
            $show->field('cover_picture');
            $show->field('goods_id');
            $show->field('anchor');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CreateLiveStream(), function (Form $form) {
            $form->display('id');
            $form->text('live_broadcast_title');
            $form->text('live_broadcast_message');
//            $form->select('anchor','选择带货主播')->options('specs');
            $form->file('cover_picture')->uniqueName()->saveFullUrl();
            $form->display('created_at');
            $form->display('updated_at');
            $form->multipleSelectTable('goods_id','商品')
                ->display('商品')
                ->from(Goodssmall::make())
                ->saving(function ($e){return $e[0];})
                ->rules('required',['required'=>'商品不可为空']);
        });
    }

    /***
     * 直播列表
     */
    public function LiveStreamList()
    {
       $data =  \App\Models\CreateLiveStream::get();
      return view('LiveStreamList',compact('data'));
    }

    /**
     * 点击直播
     */
    public function audio()
    {
        return view('/admin/audio');
    }

//    public function specs(){
//        $data = anchor::select('id','uname')->get();
//        foreach ($data as $k=>$v){
//            $datas[$k]['id']=$v['id'];
//            $datas[$k]['text'] =$v['uname'];
//        }
//        return $datas;
//    }

}
